package day9;
import java.util.*;
public class TestList {
    public static void main(String[] args) {
        List<String> list=new ArrayList<>();

        for(int i=1;i<=4;i++){
            new Thread2("线程"+i,list).start();
        }
    }
}

class Thread2 extends Thread{
    private final List<String> list;

    public Thread2(String name,List<String> l){
        super(name);
        this.list=l;
    }

    @Override
    public void run() {
        for(int i=1;i<=1000;i++){
            //synchronized (list){
                this.list.add(super.getName()+" "+i);
           // }

        }
        System.out.println(list.size());
    }
}